import { updateNode } from '../shared/utils.js';
import { reconcileChildren } from './ReactChildFiber.js';
import { renderWithHooks } from '../react/ReactHooks.js';

export function updateHostTextComponent(wip) {
  wip.stateNode = document.createTextNode(wip.props.children);
}

export function updateHostComponent(wip) {
  if (!wip.stateNode) {
    wip.stateNode = document.createElement(wip.type);
    updateNode(wip.stateNode, {}, wip.props);
  }
  reconcileChildren(wip, wip.props.children);
}

export function updateFunctionComponent(wip) {
  const { type, props } = wip;
  renderWithHooks(wip);
  const childrenVnode = type(props);
  reconcileChildren(wip, childrenVnode);
}

export function updateClassComponent(wip) {
  const { type, props } = wip;
  const instance = new type(props);
  const childrenVnode = instance.render();
  reconcileChildren(wip, childrenVnode);
}
